<?php
namespace api;
/**
 * 
 */
class Robots 
{
	
	public static function chat($msg)
	{
		$url= "http://openapi.tuling123.com/openapi/api/v2";

		$method = "POST";

		$data = [
			'reqType'=>1,
			'perception'=>[
				'inputImage'=>[
					'url'=>"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1531139971326&di=2c0e69fb01d9bfc02e8a2db1f8b2a140&imgtype=0&src=http%3A%2F%2Fztd00.photos.bdimg.com%2Fztd%2Fw%3D700%3Bq%3D50%2Fsign%3De7ebd10418dfa9ecfd2e541752eb863e%2F0823dd54564e9258c43135f69582d158ccbf4ea4.jpg"
				]
			],
			'userInfo'=>[
				'apiKey'=>'facc47b9f3afc7a493121bf6aacab53f',
				'userId'=>9090
			]
		];

		self::post($url,$method,$data);
	}

	public static function post($url,$method,$data)
	{
		$curl = curl_init();

		curl_setopt($curl, CURLOPT_URL, $url);

		curl_setopt($curl, CURLOPT_HEADER, false);

		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

		curl_setopt($curl, CURLOPT_POST,$method);

		curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));

		curl_setopt($curl, CURLOPT_HTTPHEADER, array(
		    'Content-Type: application/json',
		    'Content-Length: ' . strlen(json_encode($data))
		));

		$res = curl_exec($curl);

		$arr = json_decode($res,true);

		var_dump($arr['results']);
	}
}